package org.web.ssm.controller.wechatController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.web.ssm.dto.ResultModel;
import org.web.ssm.model.Comment;
import org.web.ssm.model.Topic;
import org.web.ssm.model.queryVo.BaseQuery;
import org.web.ssm.service.ITopicService;
import org.web.ssm.service.wechatService.IComentService;
import org.web.ssm.utils.DateUtils;

import javax.servlet.http.HttpSession;

/**
 * Created by hubin on 2016/6/15.
 */
@Controller
@RequestMapping("/commen")
public class CommenController {

    @Autowired
    private IComentService comentService;

    @RequestMapping(value = "/commomList", method = RequestMethod.POST)
    @ResponseBody
    public ResultModel<Comment> commomList(int topicid) {
        ResultModel<Comment> resultModel = new ResultModel<Comment>();
        try {

            resultModel.setMsg("查询成功！");
            resultModel.setItems(comentService.listByTopic(topicid));
            resultModel.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            resultModel.setMsg("查询成功！");
            resultModel.setSuccess(false);
        }
        return resultModel;
    }


    @RequestMapping(value = "/commomtopic", method = RequestMethod.POST)
    @ResponseBody
    public ResultModel<Comment> commomTopic(String content, int userid, int topicid) {
        ResultModel<Comment> resultModel = new ResultModel<Comment>();
        try {
            Comment comment = new Comment();
            comment.setTopicid(topicid);
            comment.setUserid(userid);
            comment.setContent(content);
            comentService.commrntTopic(comment);
            resultModel.setMsg("评论成功！");
            resultModel.setSuccess(true);

        } catch (Exception e) {
            e.printStackTrace();
            resultModel.setMsg("评论失败！");
            resultModel.setSuccess(false);
        }
        return resultModel;

    }


}
